home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / rexx / ARexxG2_0A.lha / ARexxGuide / Extras / UnCrunch.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-24  |  3KB  |  102 lines

  1. /**** UnCrunch.rexx ****************  Unarchive any file ****************
  2. **
  3. **    A tutorial example to ARexxGuide
  4. */
  5.  
  6.  arg FileName UCdir .
  7.  
  8.  if FileName = '?' then
  9.  do
  10.     options prompt 'UCR FILENAME/A, DESTINATION/F: '
  11.     pull FileName UCdir
  12.  end
  13.  
  14.  if FileName = '' then
  15.     do
  16.       call Usage('You must supply the name of a file to uncrunch.')
  17.       exit 19
  18.     end
  19.     else
  20.       if ~exists(FileName) then
  21.       do
  22.          call Usage(Can't open' FileName 'for input - object not found)
  23.          exit 20
  24.       end
  25.  if UCdir = '' then
  26.     UCdir = 'RAM:'
  27.  else
  28.     if right(UCdir, 1) ~= ':' & right(UCdir, 1) ~= '/' then
  29.        UCdir = UCdir || '/'
  30.  
  31.  ArcExt = upper(right(FileName, 3))
  32.  
  33.  address command
  34.  select
  35.     when ArcExt = 'LZH' | ArcExt = 'LHA' then
  36.        /* Substitute 'lz' for 'lha'if you prefer to use it */
  37.        'Lha -x x' FileName '#?' UcDir
  38.     when ArcExt = 'ZOO' then
  39.        call SetDest('ZOO x//')
  40.     when ArcExt = 'ARC' then
  41.        call SetDest('ARC x')
  42.     when ArcExt = 'ZIP' then
  43.        call SetDest('UNZIP')
  44.     otherwise
  45.        say FileName 'is not valid archive'
  46.        say 'Filename must end in "LZH", "LHA", "ZOO", "ZIP", or "ARC"'
  47.        exit 11
  48.  end
  49.  
  50.  exit
  51.  
  52.  
  53.    /* ZOO and ARC uncrunch all files to the current directory           **
  54.    ** The following subroutine changes the current directory to that    **
  55.    ** specified for uncrunching                                         */
  56.  
  57.  
  58.  SetDest:
  59.     parse arg AProg
  60.     cdir = pragma('D')          /* Store the current directory */
  61.  
  62.        /* Change archive filename to a path/file that can be      */
  63.        /* understood from a different directory                   */
  64.     FDir = CDir
  65.     select
  66.        when pos(':', FileName) > 1 then
  67.           FDir = ''   /* device is already specified. Don't change*/
  68.        when left(FileName, 1) == '/' then
  69.              /* Strip off leading '/' in filename */
  70.        do while left(FileName, 1) == '/'      /* is 1st char '/'? */
  71.           FileName = substr(FileName, 2)      /* strip it off     */
  72.           PLn = length(FDir) - 1
  73.           DivPos = max(lastpos('/', FDir,Pln),,
  74.                             lastpos(':', FDir, Pln))
  75.           FDir = left(FDir, DivPos)
  76.        end
  77.        when left(FileName,1) = ':' then
  78.           parse var CDir FDir ':' .
  79.        otherwise
  80.           if verify(right(FDir, 1), '/:', 'M') ~= 0 then
  81.              FDir = FDir'/'
  82.     end
  83.     FileName = FDir||FileName
  84.  
  85.        /* Perform the uncrunching                                 */
  86.     'cd "'UCdir'"'
  87.      ''AProg '"'FileName'"'
  88.     'cd "'CDir'"'
  89.  
  90.  return
  91.  
  92. Usage:
  93.    if arg(1, 'E') then
  94.       say arg(1)
  95.     say 'Usage:'
  96.     say '  ucr <filename> [destination]'
  97.     say '      <filename> must end with valid archive extension.'
  98.     say '      [destination] is the dir in which files will be uncrunched.'
  99.     say ''
  100.     exit 20
  101.  end
  102.